#include <SpammerFactoryI.h>

SpammerFactoryI::SpammerFactoryI()
{
}
 
SpammerFactoryI::~SpammerFactoryI()
{
}

FIPA::AgentPrx
SpammerFactoryI::create
(const std::string& name,
 const Ice::Current& curr)
{
  IceUtil::Mutex::Lock lock(_m);

  Ice::Identity id;
  SpammerIPtr servant;
  Test::SpammerPrx agent;

  // Create the ID.
  if (name == "")
    id = curr.adapter->getCommunicator()->stringToIdentity(IceUtil::generateUUID());
  else
    id = curr.adapter->getCommunicator()->stringToIdentity(name);

  // Register the servant.
  try
    {
      servant = new SpammerI(id, curr.adapter);
      agent = Test::SpammerPrx::
	uncheckedCast(curr.adapter->add(servant, id));
    }
  catch(const Ice::AlreadyRegisteredException&)
    {
      throw FIPA::AgentExists();
    }
  
  RMap::iterator i = _agents.begin();
  while(i != _agents.end())
    if(i->second->isZombie())
      _agents.erase(i++);
    else
      ++i;
  
  _agents[id] = servant;
  return agent;
}
 
FIPA::AgentSeq
SpammerFactoryI::createSeq
(const Ice::StringSeq&, 
 Ice::StringSeq&,
 const ::Ice::Current&)
{
}
